package com.wd.elec.controller.bussiness;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wd.elec.domain.CalendarData;
import com.wd.elec.domain.DeptAttendReport;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wd.common.core.controller.BaseController;
import com.wd.common.core.domain.HttpResponse;
import com.wd.common.annotation.Log;
import com.wd.common.enums.BusinessType;
import com.wd.elec.domain.AttendReport;
import com.wd.elec.service.IAttendReportService;
import com.wd.common.utils.poi.ExcelUtil;


/**
 * 考勤统计Controller
 * 
 * @author liumingkun
 * @date 2023-11-21
 */
@RestController
@RequestMapping("/attend/report")
public class AttendReportController extends BaseController
{
    @Resource
    private IAttendReportService attendReportService;

    /**
     * 查询考勤统计列表
     */
    @PreAuthorize("@ss.hasPermi('attend:report:list')")
    @GetMapping("/list")
    public HttpResponse list(AttendReport attendReport)
    {
        startPage();
        List<AttendReport> list = attendReportService.selectAttendReportList(attendReport);
        return HttpResponse.successData(getDataTable(list));
    }

    /**
     * 查询考勤统计列表
     */
    @PreAuthorize("@ss.hasPermi('attend:report:list')")
    @GetMapping("/dept/list")
    public HttpResponse deptList(DeptAttendReport attendReport)
    {
        startPage();
        List<DeptAttendReport> list = attendReportService.selectDeptAttendReport(attendReport);
        return HttpResponse.successData(getDataTable(list));
    }

    /**
     * 查询考勤统计列表
     */
    @PreAuthorize("@ss.hasPermi('attend:report:list')")
    @GetMapping("/staff/list")
    public HttpResponse staffList(AttendReport attendReport)
    {
        List<CalendarData> list = attendReportService.getStaffReport(attendReport);
        return HttpResponse.successData(list);
    }


    /**
     * 导出考勤统计列表
     */
    @PreAuthorize("@ss.hasPermi('attend:report:export')")
    @Log(title = "考勤统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttendReport attendReport)
    {
        List<AttendReport> list = attendReportService.selectAttendReportList(attendReport);
        ExcelUtil<AttendReport> util = new ExcelUtil<AttendReport>(AttendReport.class);
        util.exportExcel(response, list, "考勤统计数据");
    }

    /**
     * 获取考勤统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('attend:report:query')")
    @GetMapping(value = "/{reportId}")
    public HttpResponse getInfo(@PathVariable("reportId") Long reportId)
    {
        return successData(attendReportService.selectAttendReportByReportId(reportId));
    }

    /**
     * 新增考勤统计
     */
    @PreAuthorize("@ss.hasPermi('attend:report:add')")
    @Log(title = "考勤统计", businessType = BusinessType.INSERT)
    @PostMapping
    public HttpResponse add(@RequestBody AttendReport attendReport)
    {
        return getResult(attendReportService.insertAttendReport(attendReport));
    }

    /**
     * 修改考勤统计
     */
    @PreAuthorize("@ss.hasPermi('attend:report:edit')")
    @Log(title = "考勤统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public HttpResponse edit(@RequestBody AttendReport attendReport)
    {
        return getResult(attendReportService.updateAttendReport(attendReport));
    }

    /**
     * 删除考勤统计
     */
    @PreAuthorize("@ss.hasPermi('attend:report:remove')")
    @Log(title = "考勤统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public HttpResponse remove(@PathVariable Long[] reportIds)
    {
        return getResult(attendReportService.deleteAttendReportByReportIds(reportIds));
    }


    @RequestMapping("/job")
    public HttpResponse attendReportJob( Integer year, Integer month)
    {
        attendReportService.attendReportJob(year,month);
        return HttpResponse.success();
    }
}
